package com.qf.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lixu
 */
@Configuration
public class ThreadConfig {


    /**
     * 创建线程池
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                3,//核心线程
                10,//最大线程
                5,//空闲线程的存活时间
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),//阻塞队列
                Executors.defaultThreadFactory(),//
                new ThreadPoolExecutor.AbortPolicy()//默认拒绝策略
        );
        return threadPoolExecutor;
    }
}
